﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InfoPick.Lib.DataProvider;
using InfoPick.Lib.Entity;
using InfoPick.Lib.StringResolve;

namespace InfoPick.Lib.Service
{
    public class DataService
    {
        protected IDataProvider provider;
        public DataService(IDataProvider provider)
        {
            this.provider = provider;
        }

        public bool Begin()
        {
            return provider.Begin();
        }

        public void Complete()
        {
            provider.Complete();
        }

        public List<TDMIU> GetTdmiuList()
        {
            string res = provider.GetTdmiuList();
            var list = TDMIUResolver.ResolveList(res);
            return list;
        }

        public List<GMDDF> GetE32List()
        {
            string res = provider.GetE32List();
            var list = BRDResolver.ResolveGMDDF(res);
            return list;
        }

        public List<GMODF> GetS2lList()
        {
            string res = provider.GetS2lList();
            var list = BRDResolver.ResolveGMODF(res);
            return list;
        }

        public List<GSDDF> GetEpiList()
        {
            string res = provider.GetEpiList();
            var list = BRDResolver.ResolveWEPIDDF(res);
            return list;
        }

        public List<GSDDF> GetCsuList()
        {
            string res = provider.GetCsuList();
            var list = BRDResolver.ResolveWCSUDDF(res);
            return list;
        }

        public List<GSN7LNK> GetN7LNKALLList()
        {
            string res = provider.GetN7LNKALLList();
            var list = GSN7LNKResolver.ResolveList(res);
            return list;
        }

        public List<AIETKC> GetAIETKCList()
        {
            string res = provider.GetAIETKCList();
            var list = AIETKCResolver.ResolveList(res);
            return list;
        }

        public List<N7TKC> GetN7TKCList()
        {
            string res = provider.GetN7TKCList();
            var list = N7TKCResolver.ResolveList(res);
            return list;
        }


        public List<AIETG> GetAIETGList()
        {
            string res = provider.GetAIETGList();
            var list = AIETGResolver.ResolveList(res);
            return list;
        }


        public List<GMN7LNK> GetN7LNKList()
        {
            string res = provider.GetN7LNKList();
            var list = GMN7LNKResolver.ResolveList(res);
            return list;
        }

        private List<MTP2LNK> mtp2List = null;
        private bool isMtp2ListInit = false;
        private List<MTP2LNK> GetMTP2LNKList()
        {
            if (!isMtp2ListInit)
            {
                var res = provider.GetMTP2LNKAllList();
                mtp2List = MTP2LNKResolver.ResolveData(res);
                isMtp2ListInit = true;
            }
            return mtp2List;
        }

        public List<MTP2LNK> GetMTP2LNKList(int key)
        {
            var res = provider.GetMTP2LNKList(key);
            if (string.IsNullOrEmpty(res))
            {
                var list = GetMTP2LNKList();
                return list.Where(c => c.MTP2LinkNo == key).ToList();
            }
            else
            {
                return MTP2LNKResolver.ResolveDataWithKey(res);
            }
        }

        public List<CLKSRC> GetCLKSRCList()
        {
            string res = provider.GetCLKSRCList();
            var list = CLKSRCResolver.ResolveList(res);
            return list;
        }
    }
}
